<template>
  <div class="container-fuild">
    <div class="row page-titles">
      <ol class="breadcrumb">
        <li class="breadcrumb-item active">实训班 /</li>
        <li class="breadcrumb-item">项目管理</li>
      </ol>
    </div>
    <div class="row">
      <div class="card">
        <div class="card-header">
          <p class="card-title">我的项目组</p>
        </div>
        <div class="card-body custom-ekeditor">
          <div id="ckeditor">
            <el-table
                :data="tableList1"
                style="width: 100%">
              <el-table-column
                  label="实训班"
                  width="230">
                <template slot-scope="scope">
                  <span>{{ scope.row.className }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  label="项目名"
                  width="180">
                <template slot-scope="scope">
                  <span>{{ scope.row.trainingGroup.projectName }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  label="小组名"
                  width="120">
                <template slot-scope="scope">
                  <span>{{ scope.row.trainingGroup.groupName }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  label="期数"
                  width="150">
                <template slot-scope="scope">
                  <span>{{ scope.row.period }}</span>
                </template>
              </el-table-column>

              <el-table-column label="操作" >
                <template slot-scope="scope">
                  <el-button size="mini" style="background-color: #016bb7 ;color: white"
                             @click="table1Show(scope.$index, scope.row)">教师查看
                  </el-button>
                  <el-button size="mini" style="background-color: #ffc971 ;color: white"
                             @click="table3Show(scope.$index, scope.row)">分工管理
                  </el-button>
                </template>
              </el-table-column>
              <el-dialog title="教师简介" :visible.sync="dialogVisible1" style="font-weight: bold"
                         append-to-body width="60%" class="showAll_dialog" >
                <el-descriptions :column="2" border style="padding-left: 20px;padding-right: 20px">
                  <el-descriptions-item label="教师名" label-class-name="my-label" content-class-name="my-content">{{ form.teacherName }}</el-descriptions-item>
                  <el-descriptions-item label="性别">{{ form.gender }}</el-descriptions-item>
                  <el-descriptions-item label="手机号">{{ form.phone }}</el-descriptions-item>
                  <el-descriptions-item label="邮箱">{{ form.email }}</el-descriptions-item>
                  <el-descriptions-item label="职称">
                    <el-tag size="small">{{ form.title }}</el-tag>
                  </el-descriptions-item>
                </el-descriptions>
              </el-dialog>

              <el-dialog title="分工修改" :visible.sync="dialogVisible2" style="font-weight: bold ;height: 60%"
                         append-to-body width="50%"  class="showAll_dialog" >
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px" :inline="true">
                  <el-row>
                    <el-form-item prop="desc1" style="padding-left: 13px">
<!--                      <p style="font-size: 15px">对实训单位的总体评价:</p>-->
                      <el-input placeholder="请输入分工安排" style="width: 570px;" type="textarea"
                                v-model="ruleForm.desc1"></el-input>
                    </el-form-item>
                  </el-row>
                </el-form>
                <span slot="footer" class="dialog-footer">
<!--                      <el-button type="primary" @click="dialogVisible = false">确 定</el-button>-->
                      <el-button type="primary" @click="submitForm('ruleForm')"
                                 style="background-color: #016bb7">
                        修改
                      </el-button>
                      <el-button @click="resetForm('ruleForm')">重置</el-button>
                    </span>

              </el-dialog>

              <el-dialog title="小组分工管理" :visible.sync="dialogVisible3" style="font-weight: bold"
                         append-to-body width="60%" class="showAll_dialog" >
                <template >
                  <el-table
                      :data="table2"
                      style="width: 100%">

                    <el-table-column type="expand">
                      <template slot-scope="scope">
                        <el-form label-position="left" inline class="demo-table-expand">
<!--                          <el-form-item label="组内分工">-->
                            <el-descriptions :column="1" border style="padding-left: 60px;padding-right: 60px;">
                              <el-descriptions-item>
                                <template slot="label" style="color: #7d94c0; font-weight: bold">
                                  分工
                                </template>
                                  <span>{{ scope.row.division}}</span>
                                <el-button size="mini" icon="el-icon-edit-outline " @click="table2Show(scope.$index, scope.row)"
                                           style="margin-left: 10px;margin-right: 10px;border-radius: 1.250rem;"></el-button>
                              </el-descriptions-item>
                            </el-descriptions>
<!--                          </el-form-item>-->
                        </el-form>
                      </template>
                    </el-table-column>

                    <el-table-column label="组内身份" width="110">
                      <template slot-scope="scope">
                        <el-tag size="middle" :type="scope.row.identity === '组长' ? 'success' : 'info'">
                          <span>{{scope.row.identity}}</span>
                        </el-tag>
                      </template>
                    </el-table-column>
                    <el-table-column label="姓名" width="90">
                      <template slot-scope="scope">
                        <span>{{scope.row.student.studentName}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="学号" width="160">
                      <template slot-scope="scope">
                        <span>{{scope.row.student.studentId}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="年级" width="100">
                      <template slot-scope="scope">
                        <span>{{scope.row.student.grade}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="专业" width="110">
                      <template slot-scope="scope">
                        <span>{{scope.row.student.major}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="班级" width="90">
                      <template slot-scope="scope">
                        <span>{{scope.row.student.banji}}</span>
                      </template>
                    </el-table-column>
                  </el-table>
                </template>
              </el-dialog>
            </el-table>
          </div>
        </div>
      </div>
    </div>
  </div>

</template>

<script>
export default {
  data() {
    return {
      id:this.$route.query.id,
      dialogVisible1: false,
      dialogVisible2: false,
      dialogVisible3: false,
      tableList1: [],
      className: '',
      stuId:'',
      table2: [{
        identity: '组长',
        name: 'AAA',
        id:'201941404227',
        grade:'2019',
        major:'软件工程',
        class:'2班',
        work:'首页、登陆功能的前后端学生管理、教师管理、管理员后台的前端页面'
      }, {
        identity: '组员',
        name: 'BBB',
        id:'201941404227',
        grade:'2019',
        major:'软件工程',
        class:'1班',
        work: '建立数据库、学生后台管理的后端、管理员后台的后端'
      },
        {
        identity: '组员',
        name: 'CCC',
        id:'201941404227',
        grade:'2019',
        major:'软件工程',
        class:'2班'
      }],
      form:{
        teacherName:'',
        gender:'',
        phone:'',
        email:'',
        title:''
      },
      rules: {
        desc1: [
          {required: true, message: '请填写分工', trigger: 'blur'},
        ],
      },
      ruleForm: {
        desc1: '',
      },
    }
  },
  mounted() {
    this.classShow();
  },
  methods: {
    table1Show(index, row) {  //教师表单
      this.dialogVisible1 = true;
      this.className = row.className;

      let that = this;
      this.axios.get("http://localhost:9090/user/getTeacherByClass/"+this.className).then(function (ret) {
        // console.log(ret.data.data)
        that.form.teacherName=ret.data.data[0].teacherName;
        that.form.gender=ret.data.data[0].gender;
        that.form.phone=ret.data.data[0].phone;
        that.form.email=ret.data.data[0].email;
        that.form.title=ret.data.data[0].title;
        // that.form.company = ret.data.data[0].company;
        // console.log(ret.data.data[0].id)
      }).catch(function (err) {
      })
    },
    table2Show(index, row) {  //小组表单
      this.dialogVisible2 = true;
      this.className = row.className;
      this.stuId= row.student.studentId;
      let that = this;
      this.axios.get("http://localhost:9090/user/getProject/" + this.className + "/" +this.id).then(function (ret) {
        // console.log(ret.data.data)
        that.form.company = ret.data.data[0].company;
        that.form.teacherName = ret.data.data[0].teacherName;
        that.form.period = ret.data.data[0].period;
        that.form.className = ret.data.data[0].className;
        // console.log(ret.data.data[0].id)
      }).catch(function (err) {
      })
    },
    table3Show(index, row) {  //分工表单
      this.dialogVisible3 = true;
      this.className = row.className;
      let that = this;
      this.axios.get("http://localhost:9090/user/getGroupByIdClass/" + this.id + "/"+this.className)
          .then(function (ret) {
        console.log(ret.data.data)
           that.table2=ret.data.data;
      }).catch(function (err) {
      })
    },
    classShow: function () {  //显示默认的学生课程页面
      let that = this;
      this.axios.get('http://localhost:9090/user/getGroupById/'+this.id).then(function (ret) {
        // console.log(ret.data.data);
        that.tableList1 = ret.data.data;
        // that.commentStatus = ret.data.data.trainingStudent.CommentStatus;
        // console.log(ret.data.data.trainingStudent.CommentStatus);
      }).catch(function (err) {
      })
    },
    submitForm(formName) {
      let that1 = this;
      let that2 = this;
      let data = this.form;
      console.log(that2.className)
      console.log(that2.stuId)
      console.log(that2.ruleForm.desc1)
      that1.$refs[formName].validate((valid) => {
        if (valid) {

          this.$axios({
            method:'post',
            url:'http://localhost:9090/user/updateDivision',
            header:{
              'Content-type':'application/json'
            },
            data:{
              className: that2.className,
              studentId: that2.stuId,
              division: that2.ruleForm.desc1,
            },
            transformRequest:[function (data){
              let ret =''
              for (let it in data){
                ret +=encodeURIComponent(it) + '=' +encodeURIComponent(data[it]) + '&'
              }
              return ret
            }]
          }).then((res) => {
            console.log(res.data)
            alert('修改成功!');

          }).catch(function (error) {
            console.log('请求失败：' + error)
          })
          // this.dialogVisible = false;
          // this.$router.go(0);
          //   this.$axios.post('http://localhost:9090/user/updateDivision', {
          //     className: that2.className,
          //     studentId: that2.stuId,
          //     division: that2.ruleForm.desc1,
          //   }).then(res => {
          //     // console.log(data)
          //     console.log(res)
          //     alert('修改成功!');
          //   }).catch(error => {
          //     console.log('请求失败')
          //     console.log(error)
          //   })


          this.dialogVisible = false;
          this.$router.go(0);
        } else {
          console.log('error submit!!');
          return false;
        }
      })
      ;
    }
    ,
    resetForm(formName) {  //重置
      this.$refs[formName].resetFields();
    }
  }
}
</script>

<style scoped>
/*表头*/
.container-fuild {
  float: left;
  /*padding-top:1.875rem;*/
  padding-right: 1.875rem;
  padding-left: 1.875rem;
  width: 93%;
  margin-right: auto;
  margin-left: auto;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.5;
  color: #7d94c0;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

.page-titles {
  justify-content: space-between;
  /*padding: 0.1375rem 0.5rem;*/
  padding-top: 0.25rem;
  padding-right: 1.875rem;
  padding-bottom: 0.25rem;
  padding-left: 1.875rem;
  background: #fff;
  margin-bottom: 1.875rem;
  border-radius: 1rem;
  margin-top: 0;
  margin-left: 0;
  margin-right: 0;
  --bs-gutter-x: 30px;
  --bs-gutter-y: 0;
  display: flex;
  flex-wrap: wrap;
}

.page-titles .breadcrumb {
  padding: 0;
  background: transparent;
  font-size: 1.1875rem;
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  list-style: none;
  flex-shrink: 0;
  width: 100%;
  max-width: 100%;
}

.breadcrumb li.active {
  font-weight: 600;
  font-size: 1.1875rem;
}

.breadcrumb li {
  margin-top: 0;
  margin-bottom: 0;
  padding-left: 0.5rem;
  font-size: 1.1875rem;
}

/*主题部分*/
.row {
  --bs-gutter-x: 30px;
  --bs-gutter-y: 0;
  display: flex;
  flex-wrap: wrap;
  margin-top: calc(var(--bs-gutter-y) * -1);
  margin-right: calc(var(--bs-gutter-x) / -2);
  margin-left: calc(var(--bs-gutter-x) / -2);
}

.card {
  width: 100%;
  margin-bottom: 1.875rem;
  background-color: #fff;
  transition: all .5s ease-in-out;
  position: relative;
  /*border: 0rem solid transparent;*/
  border-radius: 1.25rem;
  /*box-shadow: 0rem 0.3125rem 0.3125rem 0rem rgb(82 63 105 / 5%);*/
  height: calc(100% - 30px);

  display: flex;
  flex-direction: column;
  min-width: 0;
  word-wrap: break-word;
  background-clip: border-box;
}

.card-header {
  border-color: #f5f5f5;
  position: relative;
  background: transparent;
  /*padding-top: 0rem;*/
  padding-right: 1.875rem;
  /*padding-bottom: 0rem;*/
  padding-left: 1.875rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-title {
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  font-size: 1.1rem;
  font-weight: 300;
  color: #909399;
  text-transform: capitalize;
}

.card-body {
  padding-top: 0.125rem;
  padding-right: 1.875rem;
  padding-bottom: 1.125rem;
  padding-left: 1.875rem;

  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: auto;
}

/*让dialog能够悬浮在中间*/
.showAll_dialog {
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: auto;
}

::v-deep .el-dialog {
  margin: 0 auto !important;
  height: 80%;
  overflow: auto;
  background-color: white;
}

.el-dialog__body {
  position: absolute;
  left: 0;
  top: 54px;
  bottom: 0;
  right: 0;
  z-index: 1;
  overflow: hidden;
  overflow-y: auto;

  line-height: 30px;
  padding: 15px;
}

/*弹窗标题的padding*/
::v-deep .el-dialog__header {
  padding-top: 30px;
  padding-right: 50px;
  padding-bottom: 30px;
  padding-left: 50px;
}
/*弹窗圆角*/
::v-deep .el-dialog{
  border-radius: 10px;
}

/*弹窗标题的颜色*/
::v-deep .el-dialog__title{
  color: #909399;
}

/*更换表格字体颜色*/
::v-deep .el-table{
  color: #7d94c0;
}

/*更换标签的颜色*/
.el-tag.el-tag--success {
  background-color: #ffd99b;
  border-color: #ffd99b;
  color: white;
}
.el-tag.el-tag--info {
  background-color: #97c2e1;
  border-color: #97c2e1;
  color: white;
}


/*设置折叠表单*/
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}

/*设置折叠表单里面的描述样式*/
/*::v-deep .el-descriptions {*/
/*  min-height: 30px*/
/*}*/
::v-deep .el-descriptions__body {
  color: #7d94c0;
}
::v-deep .el-descriptions-item__label.is-bordered-label {
  font-weight: 900;
  color: #7d94c0;
  background: #f5f8ff;
}

::v-deep .el-button{
  border-radius: 5px;
}
</style>